package com.mz.ozy.mvp.presenter;


import android.app.Activity;

import com.mz.ozy.base.BasePresenterImpl;
import com.mz.ozy.bean.BalanceDetailBean;
import com.mz.ozy.mvp.model.ExchangeModel;
import com.mz.ozy.mvp.view.ExchangeContract;
import com.mz.ozy.net.MyObserver;
import com.mz.ozy.utils.RxUtil;

import org.json.JSONObject;

import okhttp3.ResponseBody;

/**
 * Created by administrator on 2018/12/3.
 */
public class ExchangePresenter extends BasePresenterImpl<ExchangeContract.View> implements ExchangeContract.Presenter {

    private ExchangeModel mModel;

    public ExchangePresenter() {
        mModel = new ExchangeModel();
    }


    @Override
    public void getExchangeInfo(Activity activity) {
        mModel.getExchangeInfo(activity)
                .compose(RxUtil.rxSchedulerHelper(mView.<ResponseBody>bindToLifecycle()))
                .subscribe(new MyObserver<BalanceDetailBean>(mView) {
                    @Override
                    public void onSuccesss(BalanceDetailBean bean) {
                        mView.getExchangeInfoSuccess(bean);
                    }
                });
    }

    @Override
    public void getXgExchangeInfo(Activity activity) {
        mModel.getXgExchangeInfo(activity)
                .compose(RxUtil.rxSchedulerHelper(mView.<ResponseBody>bindToLifecycle()))
                .subscribe(new MyObserver<BalanceDetailBean>(mView) {
                    @Override
                    public void onSuccesss(BalanceDetailBean bean) {
                        mView.onXgKtSuccess(bean);
                    }
                });
    }

    @Override
    public void getKtInfo(Activity activity,String type) {
        mModel.onKtExchange(activity, type)
                .compose(RxUtil.rxSchedulerHelper(mView.<ResponseBody>bindToLifecycle()))
                .subscribe(new MyObserver<BalanceDetailBean>(mView) {
                    @Override
                    public void onSuccesss(BalanceDetailBean jsonObject) {
                        mView.onKtSuccess(jsonObject);
                    }
                });
    }

    @Override
    public void onExchange(Activity activity, String amount, String coin, String password) {
        mModel.onExchange(activity, amount, coin, password)
                .compose(RxUtil.rxSchedulerHelper(mView.<ResponseBody>bindToLifecycle()))
                .subscribe(new MyObserver<JSONObject>(mView) {
                    @Override
                    public void onSuccesss(JSONObject jsonObject) {
                        mView.onExchangeSuccess(jsonObject);
                    }
                });
    }

    @Override
    public void onComitExchange(Activity activity, String type, String amount, String password) {
        mModel.onKtExchange(activity, type, amount, password)
                .compose(RxUtil.rxSchedulerHelper(mView.<ResponseBody>bindToLifecycle()))
                .subscribe(new MyObserver<JSONObject>(mView) {
                    @Override
                    public void onSuccesss(JSONObject jsonObject) {
                        mView.onComitKtSuccess(jsonObject);
                    }
                });
    }

    @Override
    public void onExchange(Activity activity, String amount, String password) {
        mModel.onExchange(activity, amount, password)
                .compose(RxUtil.rxSchedulerHelper(mView.<ResponseBody>bindToLifecycle()))
                .subscribe(new MyObserver<JSONObject>(mView) {
                    @Override
                    public void onSuccesss(JSONObject jsonObject) {
                        mView.onExchangeSuccess(jsonObject);
                    }
                });
    }

    @Override
    public void onXqExchange(Activity activity, String amount, String password) {
        mModel.onXxqExchange(activity, amount, password)
                .compose(RxUtil.rxSchedulerHelper(mView.<ResponseBody>bindToLifecycle()))
                .subscribe(new MyObserver<JSONObject>(mView) {
                    @Override
                    public void onSuccesss(JSONObject jsonObject) {
                        mView.onXgComitSuccess(jsonObject);
                    }
                });
    }

}
